package net.ciklum.svnnotify;

import java.util.ArrayList;

import net.ciklum.svnnotify.svn.SVNNotification;
import net.ciklum.svnnotify.svn.SVNRepoConnection;

import org.tmatesoft.svn.core.SVNException;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.widget.Toast;

public class SVNNotifyService extends Service {

	public static final String EXTRA_URI = "uri";
	public static final String EXTRA_LOGIN = "login";
	public static final String EXTRA_PASSWORD = "password";
	public static final String EXTRA_NAME= "name";
	
	private SVNRepoConnection connection;
	
	@Override
	public IBinder onBind(Intent arg0) {
		// TODO Auto-generated method stub
		return null;
	}
	
	@Override
	public void onCreate() {
		super.onCreate();
	}
	
	@Override
	public void onStart(Intent intent, int startId) {
		super.onStart(intent, startId);
		try {
			connection = new SVNRepoConnection(intent.getStringExtra(EXTRA_URI),
											   intent.getStringExtra(EXTRA_LOGIN), 
											   intent.getStringExtra(EXTRA_PASSWORD));
			ArrayList<SVNNotification> list = (ArrayList<SVNNotification>) connection.getLatestRevisions();
			Toast.makeText(this, "latest rev: " + list.get(0).getMessage(), Toast.LENGTH_LONG).show();
		} catch (SVNException e) {
			e.printStackTrace();
			Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
		}
	}

}
